package com.example.weight.wormHandle.garbageDisposal.researchDevelopment;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.weight.R;
import com.example.weight.arrayAdapter.Item;
import com.example.weight.arrayAdapter.ItemAdapter;
import com.example.weight.config.Config;
import com.example.weight.util.WeightActivity;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import org.json.JSONException;
import org.json.JSONObject;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class OutcomingSceneDischargeAndSieve extends AppCompatActivity implements View.OnClickListener{
    private String name, factory;
    private TextView discharge_date;
    private TextView discharge_start;
    private TextView discharge_end;
    private TextView sieve_start;
    private TextView sieve_end;
    private Button btn_discharge_start;
    private Button btn_discharge_end;
    private Button btn_sieve_start;
    private Button btn_sieve_end;

    private SharedPreferences preferences;
    private ItemAdapter batchAdapter;
    private ItemAdapter groupAdapter;
    private List<String> batchList;
    private List<String> groupList;
    private EditText batch;
    private EditText group;
    private EditText boxNumber;
    private PopupWindow batchPopupWindow;
    private PopupWindow groupPopupWindow;
    private TitleBar titleBar;


    private TextView device1Name;
    //出料加养殖盒重量
    private TextView discharge_box_weight;
    //养殖盒重量
    private TextView box_weight;
    //出料重量
//    private TextView discharge_weight;    //后加的字段
    //虫粪重量
    private TextView insect_dung_weight_1;
    //筛上物重量
    private TextView sieve_weight;
    //轻抛物净重
    private TextView lightwaste_weight;
    //表层纤维重量
    private TextView surface_fiber_weight;
    //老虫及杂质重量
    private TextView insect_impurity_weight;

    private TextWatcher weightChange_watcher;

    private EditText remark;

    Calendar calendar= Calendar.getInstance(Locale.CHINA);
    //出料日期
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// HH:mm:ss
    Date dischargeDate = new Date(System.currentTimeMillis());
    String activeButton = new String();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent previousIntent = getIntent();
        name = previousIntent.getStringExtra("name");
        factory = previousIntent.getStringExtra("factory");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.outcoming_scene_discharge_and_sieve);

        titleBar=findViewById(R.id.titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {

            @Override
            public void onLeftClick(View v) {
                OutcomingSceneDischargeAndSieve.this.finish();
            }

            @Override
            public void onTitleClick(View v) {
            }
            @Override
            public void onRightClick(View v) {
            }
        });

        /**
         * 显示设置日期
         */
        discharge_date = findViewById(R.id.outcoming_scene_dischargeDate);
        discharge_date.setText(simpleDateFormat.format(dischargeDate));
        /**
         * 8个重量
         */
        //出料加养殖盒重量
        discharge_box_weight = findViewById(R.id.outcoming_scene_discharge_box_weight);
        //养殖盒重量
        box_weight= findViewById(R.id.outcoming_scene_box_weight);
        //出料重量
//        discharge_weight = findViewById(R.id.outcoming_scene_discharge_weight);
        //虫粪重量
        insect_dung_weight_1= findViewById(R.id.outcoming_scene_insect_dung_weight_1);
        //筛上物重量
        sieve_weight= findViewById(R.id.outcoming_scene_sieve_weight);
        //轻抛物净重
        lightwaste_weight = findViewById(R.id.outcoming_scene_lightwaste_weight);
        //表层纤维重量
        surface_fiber_weight= findViewById(R.id.outcoming_scene_surface_fiber_weight);
        //老虫及杂质重量
        insect_impurity_weight= findViewById(R.id.outcoming_scene_insect_impurity_weight);

        weightChange_watcher = new TextWatcher()  {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                //这个方法被调用，说明在s字符串中，从start位置开始的count个字符即将被长度为after的新文本所取代。在这个方法里面改变s，会报错。
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                //这个方法被调用，说明在s字符串中，从start位置开始的count个字符刚刚取代了长度为before的旧文本。在这个方法里面改变s，会报错。
            }
            @Override
            public void afterTextChanged(Editable s) {
                //这个方法被调用，那么说明s字符串的某个地方已经被改变。
                String discharge_box_weight_string = discharge_box_weight.getText().toString().equals("")? "0.00" : discharge_box_weight.getText().toString();
                String box_weight_string = box_weight.getText().toString().equals("")? "0.00" : box_weight.getText().toString();

                //四舍五入输入值再计算
                float new_net_weight = new BigDecimal((Float.parseFloat(discharge_box_weight_string) - Float.parseFloat(box_weight_string)))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
//                discharge_weight.setText(new_net_weight+"");
            }
        };

        discharge_box_weight.addTextChangedListener(weightChange_watcher);
        box_weight.addTextChangedListener(weightChange_watcher);
        discharge_start = (TextView) findViewById(R.id.discharge_start);
        discharge_start.setOnClickListener(this);
        discharge_end = (TextView) findViewById(R.id.discharge_end);
        discharge_end.setOnClickListener(this);
        sieve_start = (TextView) findViewById(R.id.sieve_start);
        sieve_start.setOnClickListener(this);
        sieve_end = (TextView) findViewById(R.id.sieve_end);
        sieve_end.setOnClickListener(this);

        btn_discharge_start = (Button) findViewById(R.id.btn_discharge_start);
        btn_discharge_end = (Button) findViewById(R.id.btn_discharge_end);
        btn_sieve_start = (Button) findViewById(R.id.btn_sieve_start);
        btn_sieve_end = (Button) findViewById(R.id.btn_sieve_end);

        btn_discharge_start.setOnClickListener(this);
        btn_discharge_end.setOnClickListener(this);
        btn_sieve_start.setOnClickListener(this);
        btn_sieve_end.setOnClickListener(this);

        device1Name = (TextView) findViewById(R.id.outcoming_scene_device_1_name);
        remark = findViewById(R.id.outcoming_scene_remark);
        /**
         *两个输入记录缓存
         */
        batch = findViewById(R.id.outcoming_scene_batch);
        group = findViewById(R.id.outcoming_scene_group);
        boxNumber = findViewById(R.id.outcoming_scene_number);
        preferences = getSharedPreferences("outcoming_scene", Context.MODE_PRIVATE);
        batchList = new ArrayList<>(preferences.getStringSet("batchList", new HashSet<>()));
        groupList = new ArrayList<>(preferences.getStringSet("groupList", new HashSet<>()));
        List<Item> batchItemList = new ArrayList<>();
        List<Item> groupItemList = new ArrayList<>();
        // Item类型list初始化
        for (String itemName : batchList) {
            batchItemList.add(new Item(itemName, R.drawable.ic_clear));
        }
        for (String itemName : groupList) {
            groupItemList.add(new Item(itemName, R.drawable.ic_clear));
        }

        // 创建ListView
        batchAdapter = new ItemAdapter(this, R.layout.adapter_item, batchItemList);
        groupAdapter = new ItemAdapter(this, R.layout.adapter_item, groupItemList);
        ListView batchListView = new ListView(this);
        batchListView.setAdapter(batchAdapter);
        batchListView.setOnItemClickListener((parent, view, position, id) -> {
            // 若有进行删除操作，更新nameList，否则nameList序号对不上
            if (batchAdapter.getDeletePos() >= 0) {
                List<Item> tempItemList = batchAdapter.getList();
                batchList.clear();
                for (Item item : tempItemList) {
                    batchList.add(item.getName());
                }
            }
            // 根据所选设置输入框文本
            String result = batchList.get(position);
            batch.setText(result);
            batchPopupWindow.dismiss();
            hideInput();
        });

        ListView groupListView = new ListView(this);
        groupListView.setAdapter(groupAdapter);
        groupListView.setOnItemClickListener((parent, view, position, id) -> {
            // 若有进行删除操作，更新nameList，否则nameList序号对不上
            if (groupAdapter.getDeletePos() >= 0) {
                List<Item> tempItemList = groupAdapter.getList();
                groupList.clear();
                for (Item item : tempItemList) {
                    groupList.add(item.getName());
                }
            }
            // 根据所选设置输入框文本
            String result = groupList.get(position);
            group.setText(result);
            groupPopupWindow.dismiss();
            hideInput();
        });


        // 获取屏幕的宽度并设置popupwindow的宽度为width,这里是根据布局控件所占的权重
        WindowManager wManager = (WindowManager) getSystemService(this.WINDOW_SERVICE);
        int width = wManager.getDefaultDisplay().getWidth() * 3 / 5;
        int height = wManager.getDefaultDisplay().getHeight() / 8;
        // 参数为 1.View 2.宽度 3.高度
        batchPopupWindow = new PopupWindow(batchListView ,width, height);
        // 设置点击外部区域可以取消popupWindow
        batchPopupWindow.setOutsideTouchable(true);

        batch.setOnFocusChangeListener((v, hasFocus) -> {
            // 设置popupWindow显示,并且告诉它显示在那个View下面
            if (hasFocus) {
                // 若聚焦到该输入框，显示下拉列表
                batchPopupWindow.showAsDropDown(batch);
            }
        });

        groupPopupWindow = new PopupWindow(groupListView ,width, height);
        // 设置点击外部区域可以取消popupWindow
        groupPopupWindow.setOutsideTouchable(true);

        group.setOnFocusChangeListener((v, hasFocus) -> {
            // 设置popupWindow显示,并且告诉它显示在那个View下面
            if (hasFocus) {
                // 若聚焦到该输入框，显示下拉列表
                groupPopupWindow.showAsDropDown(group);
            }
        });

//        //获取当天最新一条数据
//        RequestQueue queue = Volley.newRequestQueue(this);
//        String url = Config.url + "/research/dischargeAndSieve/getlast" + "?factory=" + factory;
//        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
//                new Response.Listener<String>() {
//                    @Override
//                    public void onResponse(String response) {
//                        try {
//                            JSONObject jsonObject = new JSONObject(response);
//                            Log.d("jy",response.toString());
//                            JSONObject data;
//                            if(jsonObject.get("data")!=null && !jsonObject.get("data").toString().equals("null")) {
//                                data = jsonObject.getJSONObject("data");
//                                if (!data.isNull("id")) {
//                                    discharge_date.setText(data.getString("dischargeDate"));
//                                    batch.setText(data.getString("batch"));
//                                    group.setText(data.getString("zubie"));
//                                    boxNumber.setText(data.getString("boxNumber"));
//                                    device1Name.setText(data.getString("deviceName1"));
//                                    discharge_start.setText(data.getString("dischargeStarttime"));
//                                    discharge_end.setText(data.getString("dischargeEndtime"));
//                                    sieve_start.setText(data.getString("sieveStarttime"));
//                                    sieve_end.setText(data.getString("sieveEndtime"));
//                                    discharge_box_weight.setText(data.getString("dischargeBoxWeight"));
//                                    box_weight.setText(data.getString("boxWeight"));
////                                    discharge_weight.setText(data.getString("dischargeWeight"));
//                                    insect_impurity_weight.setText(data.getString("insectImpurityWeight"));
//                                    insect_dung_weight_1.setText(data.getString("insectDungWeight1"));
//                                    sieve_weight.setText(data.getString("sieveWeight"));
//                                    //后端没有改变量名
//                                    lightwaste_weight.setText(data.getString("dischargeWeight"));
//                                    surface_fiber_weight.setText(data.getString("surfaceFiberWeight"));
//                                    remark.setText(data.getString("remark"));
//                                    Toast.makeText(OutcomingSceneDischargeAndSieve.this,
//                                            "今日已填写此表", Toast.LENGTH_SHORT).show();
//                                }
////                            } else {
////                                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
////                                Date current_time = new Date(System.currentTimeMillis());
////                                String current_time_string = simpleDateFormat.format(current_time);
////                                discharge_start.setText(current_time_string);
////                                discharge_end.setText(current_time_string);
////                                sieve_start.setText(current_time_string);
////                                sieve_end.setText(current_time_string);
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                Toast.makeText(OutcomingSceneDischargeAndSieve.this,
//                        "获取信息失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
//            }
//        });
//        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
//                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
//        queue.add(stringRequest);
    }

    public void save(View view) {
        if (discharge_start.getText().toString().equals("")) {
            Toast.makeText(this, "请填写出料开始时间", Toast.LENGTH_SHORT).show();
            return;
        }
        if (discharge_end.getText().toString().equals("")) {
            Toast.makeText(this, "请填写出料结束时间", Toast.LENGTH_SHORT).show();
            return;
        }
        if (sieve_start.getText().toString().equals("")) {
            Toast.makeText(this, "请填写筛分开始时间", Toast.LENGTH_SHORT).show();
            return;
        }
        if (sieve_end.getText().toString().equals("")) {
            Toast.makeText(this, "请填写筛分结束时间", Toast.LENGTH_SHORT).show();
            return;
        }

        if (((TextView) findViewById(R.id.outcoming_scene_device_1_name)).getText().toString().equals("")) {
            Toast.makeText(this, "请填写设备名称", Toast.LENGTH_SHORT).show();
            return;
        }
        if (((TextView) findViewById(R.id.outcoming_scene_batch)).getText().toString().equals("")) {
            Toast.makeText(this, "请填写批次", Toast.LENGTH_SHORT).show();
            return;
        }
        if (((TextView) findViewById(R.id.outcoming_scene_group)).getText().toString().equals("")) {
            Toast.makeText(this, "请填写组别", Toast.LENGTH_SHORT).show();
            return;
        }
        if (((TextView) findViewById(R.id.outcoming_scene_number)).getText().toString().equals("")) {
            Toast.makeText(this, "请填写编号", Toast.LENGTH_SHORT).show();
            return;
        }
        if (discharge_box_weight.getText().toString().equals("")) {
            Toast.makeText(this, "请填写出料加养殖盒重量", Toast.LENGTH_SHORT).show();
            return;
        }
        if (box_weight.getText().toString().equals("")) {
            Toast.makeText(this, "请填写养殖盒重量", Toast.LENGTH_SHORT).show();
            return;
        }
        if (insect_impurity_weight.getText().toString().equals("")) {
            Toast.makeText(this, "请填写老虫及杂质重量", Toast.LENGTH_SHORT).show();
            return;
        }
        if (insect_dung_weight_1.getText().toString().equals("")) {
            Toast.makeText(this, "请填写虫粪重量", Toast.LENGTH_SHORT).show();
            return;
        }
        if (sieve_weight.getText().toString().equals("")) {
            Toast.makeText(this, "请填写筛上物重量", Toast.LENGTH_SHORT).show();
            return;
        }
        if (lightwaste_weight.getText().toString().equals("")) {
            Toast.makeText(this, "请填写轻抛物净重", Toast.LENGTH_SHORT).show();
            return;
        }
        if (surface_fiber_weight.getText().toString().equals("")) {
            Toast.makeText(this, "请填写表层纤维重量", Toast.LENGTH_SHORT).show();
            return;
        }

        new AlertDialog.Builder(this)
                .setTitle("确定保存吗？")
                .setCancelable(false)
                .setNegativeButton("取消", ((dialog, which) ->
                        Toast.makeText(this, "取消保存", Toast.LENGTH_SHORT).show()))
                .setPositiveButton("确定", (dialog, which) -> {
                    SharedPreferences.Editor editor = preferences.edit();
                    // 若有进行删除操作，更新batchList
                    List<Item> tempBatchList = batchAdapter.getList();
                    if (tempBatchList.size() != batchList.size()) {
                        batchList.clear();
                        for (Item item : tempBatchList) {
                            batchList.add(item.getName());
                        }
                    }
                    // 判断该输入框内容是否已存在，不存在则加入
                    String currentBatch = batch.getText().toString();
                    if (!currentBatch.equals("") && !batchList.contains(currentBatch)) {
                        batchList.add(currentBatch);
                    }

//                  //若有进行删除操作，更新groupList
                    List<Item> tempGroupList = groupAdapter.getList();
                    if (tempGroupList.size() != groupList.size()) {
                        groupList.clear();
                        for (Item item : tempGroupList) {
                            groupList.add(item.getName());
                        }
                    }
                    // 判断该输入框内容是否已存在，不存在则加入
                    String currentGroup = group.getText().toString();
                    if (!currentGroup.equals("") && !groupList.contains(currentGroup)) {
                        groupList.add(currentGroup);
                    }

                    editor.putStringSet("batchList", new HashSet<>(batchList));
                    editor.putStringSet("groupList", new HashSet<>(groupList));
                    editor.apply();


                    //提交请求
                    RequestQueue queue = Volley.newRequestQueue(this);
                    String url = Config.url + "/research/dischargeAndSieve/add";
                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");
                                        if (code.startsWith("2"))
                                            Toast.makeText(OutcomingSceneDischargeAndSieve.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        else
                                            Toast.makeText(OutcomingSceneDischargeAndSieve.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(OutcomingSceneDischargeAndSieve.this, "保存失败", Toast.LENGTH_SHORT).show();
                            Log.d("jy", error.toString());
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {
                            Map<String, String> map=new HashMap<>();
                            map.put("dischargeDate", simpleDateFormat.format(dischargeDate));
                            map.put("batch", "S" + ((TextView) findViewById(R.id.outcoming_scene_batch)).getText().toString());
                            map.put("zubie", ((TextView) findViewById(R.id.outcoming_scene_group)).getText().toString());
                            map.put("boxNumber", ((TextView) findViewById(R.id.outcoming_scene_number)).getText().toString());
                            map.put("deviceName1", "书柜"+((TextView) findViewById(R.id.outcoming_scene_device_1_name)).getText().toString());
                            map.put("dischargeStarttime", discharge_start.getText().toString());
                            map.put("dischargeEndtime", discharge_end.getText().toString());
                            map.put("sieveStarttime", sieve_start.getText().toString());
                            map.put("sieveEndtime", sieve_end.getText().toString());
                            map.put("dischargeBoxWeight", ((TextView) findViewById(R.id.outcoming_scene_discharge_box_weight)).getText().toString());
                            map.put("boxWeight", ((TextView) findViewById(R.id.outcoming_scene_box_weight)).getText().toString());
//                            map.put("dischargeWeight", ((TextView) findViewById(R.id.outcoming_scene_discharge_weight)).getText().toString());
                            map.put("insectDungWeight1", ((TextView) findViewById(R.id.outcoming_scene_insect_dung_weight_1)).getText().toString());
                            map.put("sieveWeight", ((TextView) findViewById(R.id.outcoming_scene_sieve_weight)).getText().toString());
                            map.put("dischargeWeight", ((TextView) findViewById(R.id.outcoming_scene_lightwaste_weight)).getText().toString());
                            map.put("surfaceFiberWeight", ((TextView) findViewById(R.id.outcoming_scene_surface_fiber_weight)).getText().toString());
                            map.put("insectImpurityWeight", ((TextView) findViewById(R.id.outcoming_scene_insect_impurity_weight)).getText().toString());
                            map.put("remark", ((TextView) findViewById(R.id.outcoming_scene_remark)).getText().toString());
                            map.put("recorder",name);
                            map.put("factory",factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                })
                .show();
    }

    /**
     * 隐藏键盘
     */
    protected void hideInput() {
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        View v = getWindow().peekDecorView();
        if (null != v) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }
    /**
     * 时间选择
     * @param activity
     * @param themeResId
     * @param tv
     * @param calendar
     */
    public static void showTimePickerDialog(Activity activity, int themeResId, final TextView tv, Calendar calendar) {
        Log.d("jy","showTimePickerDialog");
        // Calendar c = Calendar.getInstance();
        // 创建一个TimePickerDialog实例，并把它显示出来
        // 解释一哈，Activity是context的子类
        new TimePickerDialog( activity,themeResId,
                // 绑定监听器
                new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        tv.setText(String.format("%02d", hourOfDay) + ":" + String.format("%02d", minute));
                    }
                }
                // 设置初始时间
                , calendar.get(Calendar.HOUR_OF_DAY)
                , calendar.get(Calendar.MINUTE)
                // true表示采用24小时制
                ,true).show();
    }
    @Override
    public void onClick(View view) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        switch (view.getId())  {
            case R.id.btn_discharge_start:
                Date date_1_start = new Date(System.currentTimeMillis());
                String s_1_start = simpleDateFormat.format(date_1_start);
                discharge_start.setText(s_1_start);
                btn_discharge_start.setEnabled(false);
                break;
            case R.id.btn_discharge_end:
                Date date_1_end = new Date(System.currentTimeMillis());
                String s_1_end = simpleDateFormat.format(date_1_end);
                discharge_end.setText(s_1_end);
                btn_discharge_end.setEnabled(false);
                break;
            case R.id.btn_sieve_start:
                Date date_2_start = new Date(System.currentTimeMillis());
                String s_2_start = simpleDateFormat.format(date_2_start);
                sieve_start.setText(s_2_start);
                btn_sieve_start.setEnabled(false);
                break;
            case R.id.btn_sieve_end:
                Date date_2_end = new Date(System.currentTimeMillis());
                String s_2_end = simpleDateFormat.format(date_2_end);
                sieve_end.setText(s_2_end);
                btn_sieve_end.setEnabled(false);
                break;
//            case R.id.btn_insectSeparate_start:
//                Date date_3_start = new Date(System.currentTimeMillis());
//                String s_3_start = simpleDateFormat.format(date_3_start);
//                insectSeparate_start.setText(s_3_start);
//                btn_insectSeparate_start.setEnabled(false);
//                break;
//            case R.id.btn_insectSeparate_end:
//                Date date_3_end = new Date(System.currentTimeMillis());
//                String s_3_end = simpleDateFormat.format(date_3_end);
//                insectSeparate_end.setText(s_3_end);
//                btn_insectSeparate_end.setEnabled(false);
//                break;
            case R.id.discharge_start:
                showTimePickerDialog(this,  2, discharge_start, calendar);
                break;
            case R.id.discharge_end:
                showTimePickerDialog(this,  2, discharge_end, calendar);;
                break;
            case R.id.sieve_start:
                showTimePickerDialog(this,  2, sieve_start, calendar);;
                break;
            case R.id.sieve_end:
                showTimePickerDialog(this,  2, sieve_end, calendar);;
                break;
//            case R.id.insectSeparate_start:
//                showTimePickerDialog(this,  2, insectSeparate_start, calendar);;
//                break;
//            case R.id.insectSeparate_end:
//                showTimePickerDialog(this,  2, insectSeparate_end, calendar);;
//                break;
            default:
                break;
        }
    }

    /**
     * 称重接口
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String weight = data.getStringExtra("weight");
        switch (activeButton){
            case "discharge_box_weight_btn":
                discharge_box_weight.setText(weight);
                break;
            case "box_weight_btn":
                box_weight.setText(weight);
                break;
            case "insect_impurity_weight_btn":
                insect_impurity_weight.setText(weight);
                break;
            case "insect_dung_weight_btn":
                insect_dung_weight_1.setText(weight);
                break;
            case "sieve_weight_btn":
                sieve_weight.setText(weight);
                break;
            case "lightwaste_weight_btn":
                lightwaste_weight.setText(weight);
                break;
            case "surface_fiber_weight_btn":
                surface_fiber_weight.setText(weight);
                break;
//            case "insect_weight_btn":
//                insect_weight.setText(weight);
//                break;
//            case "impurity_weight_btn":
//                impurity_weight.setText(weight);
//                break;
        }
    }
    public void goWeight(View view) {
        switch (view.getId()) {
            case R.id.discharge_box_weight_btn:
                activeButton = "discharge_box_weight_btn";
                break;
            case R.id.box_weight_btn:
                activeButton = "box_weight_btn";
                break;
            case R.id.insect_impurity_weight_btn:
                activeButton = "insect_impurity_weight_btn";
                break;
            case R.id.insect_dung_weight_btn:
                activeButton = "insect_dung_weight_btn";
                break;
            case R.id.sieve_weight_btn:
                activeButton = "sieve_weight_btn";
                break;
            case R.id.lightwaste_weight_btn:
                activeButton = "lightwaste_weight_btn";
                break;
            case R.id.surface_fiber_weight_btn:
                activeButton = "surface_fiber_weight_btn";
                break;
//            case R.id.insect_weight_btn:
//                activeButton = "insect_weight_btn";
//                break;
//            case R.id.impurity_weight_btn:
//                activeButton = "impurity_weight_btn";
//                break;
            default:
                break;
        }
        Intent intent = new Intent(OutcomingSceneDischargeAndSieve.this, WeightActivity.class);
        startActivityForResult(intent, 1);
    }
}